﻿#include<iostream>
#include<string>
#define maxsize 1000
using namespace std;

struct man {
	string name;
	string age;
	string  sex;
	string phonenumber;
	string houseadress;
};

struct inform {
	struct man information[maxsize];
	int mansize;
};
struct  inform person;
struct inform* p = &person;
void addperson(struct inform* p) {
	cout << "下面请输入联系人的信息" << endl;
	cout << "请输入联系人的名字" << endl;
	string name;
	cin >> name;
	p->information[p->mansize].name = name;
	cout << "请输入联系人的性别" << endl;

	cin >> p->information[p->mansize].sex;
	cout << "请输入联系人的年龄" << endl;
	cin >> p->information[p->mansize].age;
	cout << "请输入联系人的联系电话" << endl;
	cin >> p->information[p->mansize].phonenumber;
	cout << "请输入联系人的家庭住址" << endl;
	cin >> p->information[p->mansize].houseadress;
	p->mansize++;
}
void allperson1(inform* p)
{

	if (p->mansize != 0)
	{
		for (int b = 0; b < p->mansize; b++) {
			cout << "姓名是" << p->information[b].name << endl;
			cout << "性别是" << p->information[b].sex << endl;
			cout << "年龄是" << p->information[b].age << endl;
			cout << "联系电话是是" << p->information[b].phonenumber << endl;
			cout << "家庭住址是" << p->information[b].houseadress << endl;
		}
	}
	else {
		cout << "无联系人" << endl;
	}


}
void oneperson(struct inform* p, string name)
{
	int a = 0;
	for (a = 0; a < p->mansize; a++)
	{
		if (p->information[a].name == name)
		{
			break;
		}
		else
			continue;
	}
	if (p->information[a].name == name)
	{
		cout << "姓名是" << p->information[a].name << endl;
		cout << "性别是" << p->information[a].sex << endl;
		cout << "年龄是" << p->information[a].age << endl;
		cout << "联系电话是是" << p->information[a].phonenumber << endl;
		cout << "家庭住址是" << p->information[a].houseadress << endl;

	}
	else {
		cout << "没有该联系人，请输入正确姓名" << endl;
	}
}
void fixperson(struct inform* p, string name)
{
	int a = 0;
	for (a = 0; a < p->mansize; a++)
	{
		if (p->information[a].name == name)
		{
			break;
		}
		else
			continue;
	}
	int b = 0;
	if (p->information[a].name == name)
	{

		cout << "请输入要修改的信息" << endl;
		cout << "1姓名" << endl;
		cout << "2性别" << endl;
		cout << "3年龄" << endl;
		cout << "4联系电话" << endl;
		cout << "5家庭住址" << endl;
		cout << "6退出修改程序" << endl;
		while (b != 6)
		{
			cin >> b;
			switch (b) {
			case(1): {
				cin >> p->information[a].name;
				cout << "名字修改成功" << endl;
				break;
			}
			case(2): {
				cin >> p->information[a].sex;
				cout << "性别修改成功" << endl;
				break;
			}
			case(3): {
				cin >> p->information[a].age;
				cout << "年龄修改成功" << endl;
				break;
			}
			case(4): {
				cin >> p->information[a].phonenumber;
				cout << "电话修改成功" << endl;
				break;
			}
			case(5): {
				cin >> p->information[a].houseadress;
				cout << "地址修改成功" << endl;
				break;
			}
			case(6): {
				cout << "已退出修改程序" << endl;
				break;
			}
			default: {
				cout << "无效选项，请重新输入" << endl;
				continue;
			}
			}

			cout << "修改后信息如下" << endl;
			cout << "姓名是" << p->information[a].name << endl;
			cout << "性别是" << p->information[a].sex << endl;
			cout << "年龄是" << p->information[a].age << endl;
			cout << "联系电话是是" << p->information[a].phonenumber << endl;
			cout << "家庭住址是" << p->information[a].houseadress << endl;

		}
	}
	else {
		cout << "没有该联系人，请输入正确姓名" << endl;
	}
}
void deletperson(struct inform* p, string name) {

	int a = 0;
	for (a = 0; a < p->mansize; a++)
	{
		if (p->information[a].name == name)
			break;
		else
			continue;
	}
	if (p->information[a].name == name)
	{
		for (a; a < p->mansize; a++)
		{
			p->information[a] = p->information[a++];
		}
		p->mansize--;
		cout << "删除成功" << endl;
	}
	else {
		cout << "无此联系人" << endl;
	}
}
void deleteallperson(inform* p)
{
	p->mansize = 0;
	cout << "已删除全部联系人" << endl;
}
int main()
{

	cout << "欢迎来到周爷天顶信息管理系统" << endl;
	cout << "这是您的功能选项" << endl;
	cout << "输入1为添加联系人" << endl;
	cout << "输入2为显示联系人" << endl;
	cout << "输入3为查找联系人" << endl;
	cout << "输入4为修改联系人" << endl;
	cout << "输入5为删除联系人" << endl;
	cout << "输入6为清空联系人" << endl;
	cout << "输入7为退出系统" << endl;
	int a = 0;
	int b = 0;
	string personname;
	string fixname;
	string deletname;
	while (a != 7) {
		cout << "请输入您的要求" << endl;
		cin >> a;
		switch (a)
		{
		case 1:
			addperson(&person);
			break;

		case 2:
			allperson1(&person);
			break;

		case(3): {
			cout << "请输入要查找人的名字" << endl;
			cin >> personname;
			oneperson(&person, personname);
			break;
		}
		case(4): {
			cout << "请输入要修改人的名字" << endl;
			cin >> fixname;
			fixperson(&person, fixname);
			break;
		case(5): {
			cout << "请输入要删除人的名字" << endl;
			cin >> deletname;
			deletperson(&person, deletname);
		}

		case(6): {
			cout << "您将要删除全部联系人，您确认吗？" << endl;
			cout << "1->是的   2->不是" << endl;
			int choise = 0;
			cin >> choise;
			if (choise == 1) {
				deleteallperson(&person);
			}
			else if (choise == 2)
			{
				break;
			}
			else {
				cout << "请输入正确选项" << endl;
			}
		}
		case(7): {
			break;
		}
		default: {
			cout << "无效指令，请输入正确指令" << endl;
			break;
		}
		}
		}
	}

}